//
//  JAFCalenderDayCollectionViewCell.m
//  JAFDemo
//
//  Created by 阿飞 on 2018/1/24.
//  Copyright © 2018年 阿飞. All rights reserved.
//

#import "JAFCalenderDayCollectionViewCell.h"
#import "UIColor+Expanded.h"
#import "UIView+FTCornerdious.h"
@implementation JAFCalenderDayCollectionViewCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
    
        _label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        _label.font = [UIFont systemFontOfSize:14];
       
        _label.textAlignment = NSTextAlignmentCenter;
        _label.userInteractionEnabled = YES;
       // [_label setTextColor:[UIColor colorWithRed:74/255.0 green:74/255.0 blue:74/255.0 alpha:1.0]];

        [self.contentView addSubview:_label];
    }
    return self;
}
-(void)setModel:(LXCalendarDayModel *)model{
    
    _model = model;
    if (self.type==0) {
    
        self.label.text = [NSString stringWithFormat:@"%ld",model.day];
        
        [self.label setFTCornerdious:0.0];
        self.label.backgroundColor = [UIColor whiteColor];
        
        if (model.isNextMonth || model.isLastMonth) {
            self.userInteractionEnabled = NO;
            
            if (model.isShowLastAndNextDate) {
                
                self.label.hidden = NO;
                if (model.isNextMonth) {
                    self.label.textColor = model.nextMonthTitleColor? model.nextMonthTitleColor:[UIColor colorWithWhite:0.85 alpha:1.0];
                }
                
                if (model.isLastMonth) {
                    self.label.textColor = model.lastMonthTitleColor? model.lastMonthTitleColor:[UIColor colorWithWhite:0.85 alpha:1.0];
                }
                
                
            }else{
                
                self.label.hidden = YES;
            }
            
            
        }else{
            if ([self.label.text isEqualToString:@"0"]) {
                self.label.hidden = YES;
                self.userInteractionEnabled = NO;
            }else{
                
                self.label.hidden = NO;
                
                self.userInteractionEnabled = YES;
                if (model.isSelected) {
                    [self.label setFTCornerdious:self.label.frame.size.width/2];
                    self.label.backgroundColor = model.selectBackColor?model.selectBackColor:[UIColor greenColor];
                    
                    if (model.isHaveAnimation) {
                        [self addAnimaiton];
                    }
                    
                }
                self.label.textColor = model.currentMonthTitleColor?model.currentMonthTitleColor:[UIColor hexStringToColor:@"000000"];
                if (model.isToday) {
                    self.label.textColor = model.todayTitleColor?model.todayTitleColor:[UIColor redColor];
                }
            }
            
        }
        
        
    }else{
        
        self.label.text = [NSString stringWithFormat:@"%ld",model.totalMonth];
        [self.label setFTCornerdious:0.0];
        self.label.backgroundColor = [UIColor whiteColor];
        
        if ([self.label.text isEqualToString:@"0"]) {
            self.label.hidden = YES;
            self.userInteractionEnabled = NO;
        }else{
        self.label.hidden = NO;
        
        self.userInteractionEnabled = YES;
        NSString *indexPathRow = [[NSUserDefaults standardUserDefaults]objectForKey:@"indexPathRow"];
            
            
       if ([indexPathRow isEqualToString:self.label.text]) {
            [self.label setFTCornerdious:self.label.frame.size.width/2];
            self.label.backgroundColor = model.selectBackColor?model.selectBackColor:[UIColor greenColor];
            
            if (model.isHaveAnimation) {
                
                [self addAnimaiton];
                
                [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"indexPathRow"];
            }
            
        }
        self.label.textColor = model.currentMonthTitleColor?model.currentMonthTitleColor:[UIColor hexStringToColor:@"000000"];
        if (model.isToday) {
            self.label.textColor = model.todayTitleColor?model.todayTitleColor:[UIColor redColor];
         }
        }
    }

    
    
}
-(void)addAnimaiton{
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    anim.values = @[@0.6,@1.2,@1.0];
    //    anim.fromValue = @0.6;
    anim.keyPath = @"transform.scale";  // transform.scale 表示长和宽都缩放
    anim.calculationMode = kCAAnimationPaced;
    anim.duration = 0.25;                // 设置动画执行时间
    //    anim.repeatCount = MAXFLOAT;        // MAXFLOAT 表示动画执行次数为无限次
    
    //    anim.autoreverses = YES;            // 控制动画反转 默认情况下动画从尺寸1到0的过程中是有动画的，但是从0到1的过程中是没有动画的，设置autoreverses属性可以让尺寸0到1也是有过程的
    
    [self.label.layer addAnimation:anim forKey:nil];
}
@end
